package com.c.ctgproject.ui.service

import androidx.lifecycle.ViewModelProvider
import com.c.ctgproject.R
import com.c.ctgproject.base.BaseActivity
import com.c.ctgproject.entity.service.ServiceLogisticsDetailEntity
import com.c.ctgproject.entity.service.ServiceLogisticsEntity
import com.c.ctgproject.utils.*
import com.c.ctgproject.wiget.common.ServiceDetailLayout
import com.c.ctgproject.wiget.ServiceDetailPictureLayout
import kotlinx.android.synthetic.main.activity_service_order_detail.*

/**
 *作者:LiBW
 *创建日期: 2021/7/5
 *描述:物流管理详情 页面
 */
class ServiceLogisticsDetailActivity : BaseActivity() {
    private val mViewModel by lazy { ViewModelProvider(this)[ServiceLogisticsDetailViewModel::class.java] }
    private val suborderId by lazy { intent.getStringExtra(MyConstants.LGS_ID).handlerNull() }
    private val mData by lazy { intent.getSerializableExtra(MyConstants.DATA) as ServiceLogisticsEntity.DataBean.ListBean }

    override fun getLayout() = R.layout.activity_service_logistics_detail

    override fun event() {
        mViewModel.getData(suborderId)
        mViewModel.error.observe(this, {
            MyLog.d("错误:$it")
            showToast(it)
        })

        mViewModel.result.observe(this, {
            MyLog.d("物流详情回调:$it")
            handlerHttpResult(it) {
                val data = getGson().fromJson(it, ServiceLogisticsDetailEntity::class.java).data
                data?.let {
                    mContainerLL.addView(ServiceDetailLayout(this, "创建时间", mData.lgsCreateTime.handlerNull()))
                    val statue=when(mData.status){
                        "1"->"待处理"
                        "2"->"待托运"
                        "3"->"托运中"
                        "4"->"已完成"
                        "5"->"已回退"
                        else->""
                    }
                    mContainerLL.addView(ServiceDetailLayout(this, "状态", statue))
                    mContainerLL.addView(ServiceDetailLayout(this, "车主姓名", mData.carOwner.handlerNull()))
                    mContainerLL.addView(ServiceDetailLayout(this, "车主电话", mData.carPhone.handlerNull()))
                    mContainerLL.addView(ServiceDetailLayout(this, "车牌号", mData.carPlate.handlerNull()))
                    mContainerLL.addView(ServiceDetailLayout(this, "车辆所在位置", data.carAddress.handlerNull()))
                    mContainerLL.addView(ServiceDetailLayout(this, "预计拖车时间", data.planTrailerTime.handlerNull()))
                    mContainerLL.addView(ServiceDetailLayout(this, "送往企业", data.orderOwner.handlerNull()))
                    mContainerLL.addView(ServiceDetailLayout(this, "拖车司机姓名", data.trailerDriverName.handlerNull()))
                    mContainerLL.addView(ServiceDetailLayout(this, "拖车司机车牌", data.trailerPlate.handlerNull()))
                    mContainerLL.addView(ServiceDetailLayout(this, "拖车司机电话", data.trailerDriverPhone.handlerNull()))
                    mContainerLL.addView(ServiceDetailLayout(this, "实际接车时间", data.realCltTime.handlerNull()))
                    mContainerLL.addView(ServiceDetailLayout(this, "送达时间", data.finishTime.handlerNull()))

                    data.picUrl?.let abc@{ images ->
                        if (images.isEmpty()) return@abc
                        mContainerLL.addView(ServiceDetailPictureLayout(this, "业务员收车图片", images))
                    }

                }
            }
        })
    }

    override fun click() {

    }
}